package com.huluobo.a2107mvpimdemo.utils;

import com.huluobo.a2107mvpimdemo.pay.Base64;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5加密工具类
 * 将一个字符串转换成一个32位的加密字符串,可以验证,相同字符串通过md5加密后,产生的字符串相等
 * Created by LC on 2023/10/8.
 */
public class Md5Utils {

    public static String encoderByMd5(String str) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            String newStr = Base64.encode(md5.digest(str.getBytes("utf-8")));
            return newStr;
        } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

    }
}
